package com.teach.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teach.Excption.UserLockedException;
import com.teach.entity.LoginUser;
import com.teach.entity.user;
import com.teach.service.UserService;
import com.teach.service.impl.UserServiceImpl;

public class LoginServlet extends HttpServlet{

	private UserService userService = new UserServiceImpl();
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String userName = request.getParameter("userName");
		String userPwd = request.getParameter("userPwd");
		try {
			user u=userService.login(userName, userPwd);
			request.getSession().setAttribute(com.teach.service.impl.Const.LOGIN_USER_SESSION_NAME, u);
			response.sendRedirect(request.getContextPath()+"/");
			return;
		} catch(Exception ex){
			ex.printStackTrace();//记调试日志
			request.setAttribute("error", ex.getMessage());
		}
		
		//跳转到视图
		request.getRequestDispatcher("/msg.jsp").forward(request, response);
		
	}
}
